﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;


namespace pigs
{
    public class Achievment
    {
        public Texture2D image;
        public Boolean achived;
        public String details;
        public Vector2 position;

        public Achievment(String des)
        {
            this.details = des;
            achived = false;
            position = new Vector2(0, 0);
        }

        public int GetNthIndex(string s, char t, int n)
{
    int count = 0;
    for (int i = 0; i < s.Length; i++)
    {
        if (s[i] == t)
        {
            count++;
            if (count == n)
            {
                return i;
            }
        }
    }
    return -1;
}

        public void Draw(SpriteBatch spritebatch, Color color, SpriteFont font, Boolean big)
        {
            int count = (details.Split(' ').Length)/2;
            int split = GetNthIndex(details, ' ', count);

            string d1 = details.Substring(0, split);
            string d2 = details.Remove(0, split + 1);

            Vector2 size = font.MeasureString(d1);
            Vector2 textPosition = new Vector2(this.position.X + this.image.Width / 2 - size.X / 2, this.position.Y + 110);
            spritebatch.DrawString(font, d1, textPosition, color);

            size = font.MeasureString(d2);
            textPosition = new Vector2(this.position.X + this.image.Width / 2 - size.X / 2, this.position.Y + 130);
            if (big) textPosition.Y += 15;
            spritebatch.DrawString(font, d2, textPosition, color);

            if (achived)
            {
                spritebatch.Draw(image, position, color);
            }
            else
            {
                color = color * .3f;
                spritebatch.Draw(image, position, color);
            }
        }
    }
}
